/**
 * 根据主机的hostName 设置请求地址
 * @returns {string}
 */
function getLinkUrl() {
  const currentHost = window.location.host;
  let LinkUrl;
  if (
    window.location.hostname == "localhost" ||
    window.location.hostname == "127.0.0.1" ||
    window.location.hostname == "local.admin.banlingkit.com"
  ) {
    LinkUrl = "http://localhost:63342/banlingkit-web/?id=";
   // LinkUrl = "http://127.0.0.1:8080/?id=";
  } else {
    LinkUrl = "http://complaint.banlingkit.com/?id=";
  }
  return LinkUrl;
}

/**
 * 根据主机的hostName 设置请求地址
 * @returns {string}
 */

function getBaseUrl() {
  const currentHost = window.location.host;
  let baseUrl;

  if (
    window.location.hostname == "localhost" ||
    // window.location.hostname == "127.0.0.1" ||
    window.location.hostname == "local.admin.banlingkit.com"
  ) {
    baseUrl = "http://localhost:8012";
  } else {
    baseUrl = `http://admin.banlingkit.com:8012`;
  }
  return baseUrl;
}

const $axios = axios.create({
  timeout: 70000,
  headers: {},
});


$axios.interceptors.request.use(
  function (config) {
    config.baseURL = getBaseUrl();
    // 在发送请求之前做些什么
    return config;
  },
  function (error) {
    // 对请求错误做些什么
    alert("Request failed. Please try again");
    return Promise.reject(error);
  }
);

// 添加响应拦截器
$axios.interceptors.response.use(
  function (response) {
    // 对响应数据做点什么
    if (response.status !== 200) {
      alert("Request failed. Please try again");
      return;
    }
    return response.data;
  },
  function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
  }
);
